home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / Developer Documentation / Recipes, Tech Notes & Articles / Recipes / Dynamic Binding / Loading Part Editors < prev   
Encoding:
Text File  |  1995-11-06  |  3.8 KB  |  79 lines  |  [TEXT/ttxt]

  1. OpenDoc™ Recipes
  2.  
  3.  
  4. Loading Part Editors Recipe
  5. By The OpenDoc Design Team
  6.  
  7. © 1993-1995  Apple Computer, Inc. All Rights Reserved.
  8. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  9. Mac and OpenDoc are trademarks of Apple Computer, Inc.
  10.  
  11.  
  12. Introduction
  13.  
  14. After the OpenDoc Name Binding process has determined what part editor or part viewer is to be used in order to edit or view a given part or document,  an editor must be loaded and a part instantiated.  Please see the Binding and ‘nmap’ Recipe for information on how to set up an editor to be recognized by the OpenDoc Name Binding system.  This recipe describes what code is required in order for an editor to be loaded under System Object Model™ for Mac™ OS (SOM for Mac).
  15.  
  16. Part Editor Loading
  17.  
  18. OpenDoc part editors are built as System Object Model (SOM) class libraries.  SOM for Mac is written on top of the Code Fragment Manager (CFM).  Therefore, there are a couple of things that are required in order for an OpenDoc editor shared library to be loaded and instantiated.
  19.  
  20.  
  21. The CFM Connection Initialization Routine
  22.  
  23. Implementing a CFM Connection Initialization Routine (documented in Inside Macintosh: PowerPC System Software) is technically optional for OpenDoc, however there are certain situations where an editor will require it.  
  24.  
  25. The most likely need for the CFM intialization function will be when  an editor  makes use of some of the OpenDoc utilty calls.  For example, if an editor is using Macintosh resources, and is using the recommended OpenDoc resource utility calls, InitLibraryResources must be called from the CFM initialization function.   (Note: using the OpenDoc resource utilties is not a requirement for using Macintosh resources in OpenDoc.  Please see Inside Macintosh: PowerPC System Software for more information on using resources from a shared library if these utilites are not going to be used.)  Likewise, if an editor is going to use any the optional ODMemory utility calls,  the CFM initialization function is a goodplace for calling InitODMemory.  See the OpenDoc utilities documentation for more information on these and other OpenDoc utilities.  
  26.  
  27.  It is also possible (but less likely) that an editor will want to make direct SOM calls in the CFM intialization function.  See the  SOMobjects™ for Mac™ OS documentation for more information on calling SOM utilties.
  28.  
  29. The following is a sample CFM intialization function:
  30.  
  31. extern "C" pascal OSErr SamplePartCFMInit(CFragInitBlockPtr initBlkPtr)
  32. {
  33.     // We are using ODMemory utility calls, so we will
  34.     // initialize the interface to the memory manager.
  35.     OSErr err1 = InitODMemory();
  36.     // We must also capture the relevant information about
  37.     // our library file so that we may access our resources.
  38.     OSErr err2 = InitLibraryResources(initBlkPtr);
  39.  
  40.     return (OSErr) (err1 != noErr) ? err1 : err2;
  41. }
  42.  
  43.  
  44. The 'cfrg' Resource
  45.  
  46. A requirement for getting SOM to instantiate a part by name is a 'cfrg' resource that contains a fragment description corresponding the SOM Class ID (or the OpenDoc Editor ID) for an editor in a shared library.  Some development systems will create a default 'cfrg' using the shared library's file name as the name of the fragment.  SOM, however, needs the Class ID in the fragment, so another name needs to be added to any existing 'cfrg'.  Note, also, that 'cfrg's differ on 68k and on PowerPC.  The following is the PowerPC 'cfrg' resource from the editor for the OpenDoc EditorSetup Control panel:
  47.  
  48. resource 'cfrg' (0) {
  49.     {    /* array memberArray: 2 elements */
  50.         /* [1] */
  51.         kPowerPC,
  52.         kFullLib,
  53.         kNoVersionNum,
  54.         kNoVersionNum,
  55.         kDefaultStackSize,
  56.         kNoAppSubFolder,
  57.         kIsLib,
  58.         kOnDiskFlat,
  59.         kZeroOffset,
  60.         kWholeFork,
  61.         "Apple::ODEditorSetup",
  62.         /* [2] */
  63.         kPowerPC,
  64.         kFullLib,
  65.         kNoVersionNum,
  66.         kNoVersionNum,
  67.         kDefaultStackSize,
  68.         kNoAppSubFolder,
  69.         kIsLib,
  70.         kOnDiskFlat,
  71.         kZeroOffset,
  72.         kWholeFork,
  73.         "ODEditorSetup"
  74.     }
  75. };
  76.  
  77.  
  78.  
  79.